<!DOCTYPE html>
<html>
<head>
<script src="/js-test-resources/js-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description("Test that readyState is CLOSED within onerror event");
window.jsTestIsAsync = true;

var ws = null;

function doTest()
{
    debug("Test start (Port 8880)");

    // This URL must return a 404 error.
    var url = "ws://127.0.0.1:8880/non-existent-url"

    ws = new WebSocket(url);

    ws.onopen = function()
    {
        testFailed("Connected");
        finishJSTest();
    };

    ws.onerror = function()
    {
        shouldBe("ws.readyState", "3");
    };

    ws.onclose = function()
    {
        finishJSTest();
    }
}

doTest();

</script>
</body>
</html>
